package com.cqust.wdm.emsboot.service.impl;

import com.cqust.wdm.emsboot.domain.Retake;
import com.cqust.wdm.emsboot.domain.User;
import com.cqust.wdm.emsboot.mapper.OrderMapper;
import com.cqust.wdm.emsboot.mapper.RetakeMapper;
import com.cqust.wdm.emsboot.service.IRetakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 退货单Service业务层处理
 *
 * @author author__

 */
@Service
public class RetakeServiceImpl implements IRetakeService {
    @Autowired
    private RetakeMapper retakeMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private MailServiceImpl mailService;

    /**
     * 查询退货单
     *
     * @param id 退货单主键
     * @return 退货单
     */
    @Override
    public Retake selectRetakeById(Long id) {
        return retakeMapper.selectRetakeById(id);
    }

    /**
     * 查询退货单列表
     *
     * @param retake 退货单
     * @return 退货单
     */
    @Override
    public List<Retake> selectRetakeList(Retake retake) {
        System.out.println(retake);
        return retakeMapper.selectRetakeList(retake);
    }

    /**
     * 新增退货单
     *
     * @param retake 退货单
     * @return 结果
     */
    @Override
    public int insertRetake(Retake retake) {
        // 查询用户信息
        User user = orderMapper.selectUserByRetake(retake);
        System.out.println(user);
        // 发送邮件，通知客户
        System.out.println("模拟发送邮件"+user.getEmail());

        mailService.send("退货消息",retake.toString());
        return retakeMapper.insertRetake(retake);
    }

    /**
     * 修改退货单
     *
     * @param retake 退货单
     * @return 结果
     */
    @Override
    public int updateRetake(Retake retake) {
        return retakeMapper.updateRetake(retake);
    }

    /**
     * 批量删除退货单
     *
     * @param ids 需要删除的退货单主键
     * @return 结果
     */
    @Override
    public int deleteRetakeByIds(Long[] ids) {
        return retakeMapper.deleteRetakeByIds(ids);
    }

    /**
     * 删除退货单信息
     *
     * @param id 退货单主键
     * @return 结果
     */
    @Override
    public int deleteRetakeById(Long id) {
        return retakeMapper.deleteRetakeById(id);
    }
}
